import 'dart:convert';

import 'package:aqua_plunge/model/hbstrategyModel.dart';
import 'package:flutter/cupertino.dart';

import '../http/Url.dart';
import 'package:http/http.dart' as http;

import '../util/header_util.dart';

///策略下发模块
class PolicyDao {
  static Utf8Decoder utf8decoder = const Utf8Decoder();

  ////获取客服的用户id
  static Future getStrategy() async {
    var uri = Uri.parse(AppUrl.getStrategy);
    var headers = await HeaderUtil().getHeader(config: true);

    var response = await http.get(uri, headers: headers);
    String bodyString = utf8decoder.convert(response.bodyBytes);

    if (response.statusCode == 200) {
      var result = json.decode(bodyString);
      HBStrategyModel configModel = HBStrategyModel.fromJson(result['data']);
      debugPrint("========${configModel.userServiceAccountId}");
    } else {
      throw Exception('"Request failed with status: ${response.statusCode}"');
    }
  }

  ///融云token接口
  static Future getRongCloudToken() async {
    var uri = Uri.parse(AppUrl.getRongCloudToken);

    var response = await http.get(uri,
        headers: await HeaderUtil().getHeader(config: true));
    String bodyString = utf8decoder.convert(response.bodyBytes);

    if (response.statusCode == 200) {
      var result = json.decode(bodyString);

      ///todo 初始化融云
    } else {
      throw Exception('"Request failed with status: ${response.statusCode}"');
    }
  }
}
